/**
 * 通用表单验证规则
 * 集中管理所有表单验证规则，实现复用
 */

export const usernameRules = [
  { required: true, message: '请输入用户名', trigger: 'blur' },
  { min: 3, max: 50, message: '用户名长度必须在3-50个字符之间', trigger: 'blur' },
  { pattern: /^[a-zA-Z0-9_]+$/, message: '用户名只能包含字母、数字和下划线', trigger: 'blur' }
];

export const passwordRules = [
  { required: true, message: '请输入密码', trigger: 'blur' },
  { min: 8, message: '密码长度不能少于8个字符', trigger: 'blur' },
  { pattern: /^(?=.*[A-Za-z])(?=.*\d).+$/, message: '密码必须包含字母和数字', trigger: 'blur' }
];

export const optionalPasswordRules = [
  { min: 8, message: '密码长度不能少于8个字符', trigger: 'blur' },
  { pattern: /^(?=.*[A-Za-z])(?=.*\d).+$/, message: '密码必须包含字母和数字', trigger: 'blur' }
];

export const nameRules = [
  { required: true, message: '请输入姓名', trigger: 'blur' },
  { min: 2, max: 20, message: '姓名长度必须在2-20个字符之间', trigger: 'blur' }
];

export const emailRules = [
  { required: true, message: '请输入邮箱', trigger: 'blur' },
  { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
];

export const phoneRules = [
  { required: true, message: '请输入电话', trigger: 'blur' },
  { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
];
export const rolenameRules=[
{ required: true, message: '请输入角色名称', trigger: 'blur' },
    { min: 2, max: 50, message: '角色名称长度应在2-50个字符之间', trigger: 'blur' },
    { pattern: /^[a-zA-Z0-9_]+$/, message: '角色名称只能包含字母、数字和下划线', trigger: 'blur' }
]
export const roleRules = [
  { required: true, message: '请选择角色', trigger: 'change' }
];
export const descriptionRules = [
    { max: 200, message: '角色描述不能超过200个字符', trigger: 'blur' }
];
export const permissionRules = [
  { required: true, message: '请至少选择一项权限', trigger: 'change' },
    { type: 'array', min: 1, message: '请至少选择一项权限', trigger: 'change' }
]

// 组合规则 - 用于完整用户表单
export const userFormRules = {
  username: usernameRules,
  name: nameRules,
  password: passwordRules,
  email: emailRules,
  phone: phoneRules,
  role: roleRules
};

// 组合规则 - 用于用户编辑表单（密码可选）
export const userEditFormRules = {
  username: usernameRules,
  name: nameRules,
  newPassword: optionalPasswordRules,
  email: emailRules,
  phone: phoneRules,
  role: roleRules
};
// 组合规则 - 用于角色表单
export const roleformRules = {
  name: rolenameRules,
  description: descriptionRules,
  permissions: permissionRules
};